package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.adapter.PopAreaAdapter;
import com.jxwifi.cloud.quickclean.bean.TagsBean;
import com.popwindow.BasicPopmodule;

import java.util.ArrayList;
import java.util.List;

public class PopAreaModule extends BasicPopmodule {

    private PopAreaListener poplistener;
    private List<TagsBean> mTagsBean = new ArrayList<>();
    private PopAreaAdapter mAdapter;
    private int mAreaindex;

    public PopAreaModule(Context ctx, List<TagsBean> mTagsBean,int areaindex, PopAreaListener l) {
        mContext = ctx;
        poplistener = l;
        this.mTagsBean = mTagsBean;
        mAreaindex=areaindex;
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_aera_module, new LinearLayout(mContext), false);
        setListener();
    }

    private void setListener() {
        View mVwPopBlan = (View) mContentView.findViewById(R.id.vw_pop_blank);
        TextView mTvPopRecordCancel = (TextView) mContentView.findViewById(R.id.tv_pop_area_cancel);
        RecyclerView mRvPopPreferModule = (RecyclerView) mContentView.findViewById(R.id.rv_pop_area_list);
        mRvPopPreferModule.setLayoutManager(new GridLayoutManager(mContext, 2));
        mRvPopPreferModule.setAdapter(mAdapter = new PopAreaAdapter(R.layout.pop_area_list_item,mAreaindex));
        mAdapter.setNewData(mTagsBean);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                poplistener.AreaClickTv(position);
                mPopwindows.dismiss();
            }
        });
        mVwPopBlan.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
        mTvPopRecordCancel.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
    }

    public interface PopAreaListener {
        void AreaClickTv(int position);
    }
}
